package ru.spb.bragnikita.myevents.composite;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 * @author Nikita.Brazhnikov
 */
@Named("login_bean")
@RequestScoped
public class LoginBean {

	@Inject
	UserVerificationBean verificationBean;

	//IN - OUT
	private String login;
	//IN
	private String password;
	//OUT
	private boolean status;
	//OUT
	private String statusDescription;

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isStatus() {
		return status;
	}

	public String getStatusDescription() {
		return statusDescription;
	}

	public String check() {
		UserVerificationBean.STATUS status = verificationBean.verify(login, password);
		if (status == UserVerificationBean.STATUS.OK) {
			this.status = true;
			return "secret_info";
		} else {
			this.status = false;
			if (status == UserVerificationBean.STATUS.INCORRECT_PASSWORD)
				this.statusDescription = "Incorrect password";
			else this.statusDescription = "User " + login + " not found";
			return null;
		}

	}

}
